<?php
//Srinivas Tamada http://9lessons.info
//Wall_Updates

class Wall_Updates {


    
     // Updates   	
	  public function Updates($uid) 
	{
	    $query = mysql_query("SELECT W.postID, W.fromID, W.message, W.postTime, A.name FROM walldb W, accountdb A  WHERE W.fromID=A.userID and W.fromID='$uid' order by W.postID desc ") or die(mysql_error());
         while($row=mysql_fetch_array($query))
		$data[]=$row;
	    return $data;
		
    }
	//Comments
	   public function Comments($msg_id) 
	{
	    $query = mysql_query("SELECT C.commentID, C.fromID, C.comment, C.commentTime, A.name FROM commentdb C, accountdb A WHERE C.fromID=A.userID and C.msgID='$msg_id' order by C.commentID asc ") or die(mysql_error());
	   while($row=mysql_fetch_array($query))
	    $data[]=$row;
        if(!empty($data))
		{
       return $data;
         }
	}
	
	//Avatar Image
	public function Gravatar($uid) 
	{
	/*
	    $query = mysql_query("SELECT picture FROM `accountdb` WHERE userID='$uid'") or die(mysql_error());
	   $row=mysql_fetch_array($query);
	   if(!empty($row))
	   {
		$data=$row;
		return $data;
         }
		 else
		 {
		 $data="image/default.jpg";
		return $data;
		 }
		 */
		 $data="image/default.jpg";
		return $data;
	}
	
	//Insert Update
	public function Insert_Update($uid, $update) 
	{
	$update=htmlentities($update);
	   $time=time();
	   $ip=$_SERVER['REMOTE_ADDR'];
        $query = mysql_query("SELECT postID,message FROM `walldb` WHERE fromID='$uid' order by postID desc limit 1") or die(mysql_error());
        $result = mysql_fetch_array($query);
		
        if ($update!=$result['message']) {
            $query = mysql_query("INSERT INTO `walldb` (message, fromID, postTime) VALUES ('$update', '$uid', '$time')") or die(mysql_error());
            $newquery = mysql_query("SELECT W.postID, W.fromID, W.message, W.postTime, A.name FROM walldb W, accountdb A where W.fromID=A.userID and W.fromID='$uid' order by W.postID desc limit 1 ");
            $result = mysql_fetch_array($newquery);
			 return $result;
        } 
		else
		{
				 return false;
		}
		
       
    }
	
	//Delete update
		public function Delete_Update($uid, $msg_id) 
	{
	    $query = mysql_query("DELETE FROM `commentdb` WHERE msgID = '$msg_id' ") or die(mysql_error());
        $query = mysql_query("DELETE FROM `walldb` WHERE postID = '$msg_id' and fromID='$uid'") or die(mysql_error());
        return true;
      	       
    }
	
	//Insert Comments
	public function Insert_Comment($uid,$msg_id,$comment) 
	{
	$comment=htmlentities($comment);
	   	    $time=time();
	   $ip=$_SERVER['REMOTE_ADDR'];
        $query = mysql_query("SELECT commentID,comment FROM `commentdb` WHERE fromID='$uid' and msgID='$msg_id' order by commentID desc limit 1 ") or die(mysql_error());
        $result = mysql_fetch_array($query);
    
		if ($comment!=$result['comment']) {
            $query = mysql_query("INSERT INTO `commentdb` (comment, fromID,msgID,commentTime) VALUES ('$comment', '$uid','$msg_id','$time')") or die(mysql_error());
            $newquery = mysql_query("SELECT C.commentID, C.fromID, C.comment, C.msgID, C.commentTime, A.name FROM commentdb C, accountdb A where C.fromID=A.userID and C.fromID='$uid' and C.msgID='$msg_id' order by C.fromID desc limit 1 ");
            $result = mysql_fetch_array($newquery);
         
		   return $result;
        } 
		else
		{
		return false;
		}
       
    }
	
	//Delete Comments
		public function Delete_Comment($uid, $com_id) 
	{
	    $query = mysql_query("DELETE FROM `commentdb` WHERE fromID='$uid' and commentID='$com_id'") or die(mysql_error());
        return true;
      	       
    }

    

}

?>
